package logic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"group-card/common/constant"
	"group-card/model/entity"
	"group-card/rpc/card/cardclient"
	"group-card/rpc/card/internal/svc"
)

type BindingFindOneLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBindingFindOneLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BindingFindOneLogic {
	return &BindingFindOneLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *BindingFindOneLogic) BindingFindOne(in *cardclient.BindingFindOneRequest) (*cardclient.BindingFindOneResponse, error) {
	var ctx context.Context
	data, err := l.svcCtx.BindingModel.FindOne(ctx, &entity.CardBindingReq{
		Id: in.Id,
	})
	if err != nil {
		return nil, err
	}

	binding := &cardclient.BindingFindOneResponse{
		Id:            data.Id,
		CardNumber:    data.CardNumber,
		CustomerId:    data.CustomerId,
		UserId:        data.UserId,
		BindingTime:   data.BindingTime.Format(constant.YMDHIS),
		FaceValue:     data.FaceValue,
		Balance:       data.Balance,
		Status:        data.Status,
		ServiceNumber: data.ServiceNumber,
	}

	return binding, nil
}
